﻿using System.Collections.Generic;
using W.Models.DataAccess;
using W.Models.Utils;

namespace W.Component
{
    public class ReservasAulasComponent : ReservasComponent<ReservasAulas>
    {
        public void SecureCreate(ReservasAulas Entity)
        {
            if (IsValid(Entity).Success)
            {
                this.Create(Entity);
                this.Response.Success = true;
            }
        }

        public Response IsValid(ReservasAulas Entity)
        {
            this._IsValid(Entity);
            return this.Response;
        }

        private void _IsValid(ReservasAulas Entity)
        {
            List<ReservasAulas> Reservas = this.Get(t => t.EstadosReserva.id == 0).FindAll(t => t.Aulas.id == Entity.Aulas.id);

            this.IsValidDateTimes(Entity);
            if (!this.Response.Success) return;

            if (Reservas != null)
            {
                HasNotTimeConfict(Reservas, Entity);
                if (!this.Response.Success) return;
            }
        }

        private List<ReservasAulas> GetByCurrentUsername()
        {
            return this.Get(t => t.Usuarios.username == CurrentUser.Name);
        }
    }
}
